package com.atguigu.gmall.controller;

import com.atguigu.gmall.model.cart.CartInfo;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.client.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * ClassName: CartController
 * Package: com.atguigu.gmall.controller
 * Description:
 *
 * @Author 刘轩
 * @Create 2023-09-01 18:27
 * @Version 1.0
 */

@Controller
public class CartController {
 @Autowired
 private ProductFeignClient productFeignClient;

 /**
  * 查看购物车
  * @return
  */
 @RequestMapping("cart.html")
 public String index(){
  return "cart/index";
 }
 /**
  * 添加购物车
  * @param skuId
  * @param skuNum
  * @param request
  * @return
  */
 @GetMapping ("addCart.html")
 public String addCart(HttpServletRequest request){
  SkuInfo skuInfo = productFeignClient.getSkuInfo(Long.parseLong(request.getParameter("skuId")));
  request.setAttribute("skuInfo",skuInfo);
  // 存储购买数量
  request.setAttribute("skuNum",request.getParameter("skuNum"));
  // 返回添加成功页面
  return "cart/addCart";
 }

}
